home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group96a.txt
/
000138_icon-group-sender _Tue Jun 18 12:57:40 1996.msg
< prev
next >
Wrap
Internet Message Format
|
1996-09-05
|
3KB
Received: by cheltenham.cs.arizona.edu; Tue, 18 Jun 1996 13:13:45 MST
Message-Id: <9606181957.AA24809@ cynic.org>
To: Hamish Lawson <H.Lawson@tees.ac.uk>
Cc: icon-group@cs.arizona.edu
Subject: Re: Locking files
In-Reply-To: Your message of Tue, 18 Jun 1996 13:11:43 BST.
<31C69CFF.6292@tees.ac.uk>
Date: Tue, 18 Jun 1996 12:57:40 -0700
From: Perry The Cynic <perry@sutr.cynic.org>
Errors-To: icon-group-errors@cs.arizona.edu
Status: O
>> there is a cheap way of locking something
>> globally used for ages: the *creation* of a special "lock" file
>> just before entering the critical section (if it is absent,
>> otherwise sleep/wait), and the destruction after.
> Is there not a small risk that in the time between some process finding
> that the lock file doesn't exist and creating this file, another process
> might also find that the lock file doesn't exist, thereby breaking the
> exclusivity mechanism.
For the "lockfile trick" to work between two "lockers", the operating
service/system interface must provide "atomic create"; that is, "create
this file if it doesn't exist, but fail if it does, atomically." All UNIXes
(that I know of) allow this (the O_EXCL flag to the open() system call),
and most other operating systems have equivalent functionality (even MS-DOS).
On a system that does *not* have this feature, the lockfile trick is
not (completely) safe.
Icon models its open() function on the UNIX fopen() routine, which
(for historic reasons) does not *portably* provide access to the
underlying O_EXCL open() flag. Thus, creating a lockfile using Icon's
standard open() function is not (completely) safe. This is not really
a failure of Icon, since it is supposed to provide *portable* access
to whatever system it runs on -- some of which may not support atomic
file creation at all.
There are other warts on the "simple" lockfile idea. If a process dies
unexpectedly (say, killed by system crash or operator), a stale lockfile
may be left behind. For a robust system, you must therefore encode
extra information (e.g. the process id of the owner) to check for stale
lockfiles and recover from them. That in turn is becoming quite system
dependent (checking whether a process is alive, choosing timeout
periods, etc.), not to mention interesting in the presence of network file
systems.
-- perry
---------------------------------------------------------------------------
Perry The Cynic perry@cynic.org
To a blind optimist, an optimistic realist must seem like an Accursed Cynic.
---------------------------------------------------------------------------